﻿#parse("/layout/header.htm")
<style>
    .file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
    }
    .file input {
        position: absolute;
        font-size: 100px;
        right: 0;
        top: 0;
        opacity: 0;
    }
    .file:hover {
        background: #AADFFD;
        border-color: #78C3F3;
        color: #004974;
        text-decoration: none;
    }
</style>
<script>
    var tupianlink1 = "$!ad0.url";
    var tupianlink2 = "$!ad1.url";
    var tupianlink3 = "$!ad2.url";

    function selectad(index) {
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                //tupianlink = localIds[0];
                //$("#imgad1").attr("src", localIds[0]);
                //$("#imgad1").attr("width", "100%");
                //$("#imgad1").attr("height", "119px");
                savetupian(res.localIds[0],index);
            }
        });
    }

    function savetupian(tupian,index) {
        wx.uploadImage({
            localId: tupian.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
            isShowProgressTips: 1, // 默认为1，显示进度提示
            success: function (res) {

                var serverId = res.serverId; // 返回图片的服务器端ID
                $.get("upload?t=" + escape( serverId), function (ret) {

                    if (ret[0] == '/') {
                        if(index==1)tupianlink1 = ret;
                        if(index==2)tupianlink2 = ret;
                        if(index==3)tupianlink3 = ret;
                        $("#imgad"+index).attr("src", ret);
                    } else {
                        alert(ret);
                    }
                });
            }
        });
    }
</script>
<title>更换广告</title>
<div data-role="page" id="page">
    <div data-role="content">
        
        <p>广告1（点击图片更换,建议图片大小是:640*120)<br/>
        <a class="file">
            <img src="$!ad0.url" style="width: 100%;" id="imgad1" />
        </a>
        <input type="text" style="width: 100%;" id="txtad1" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad0.link" />
        </p>

        
        <p>广告2$funhelper.encode($yonghu.style,"1","（点击图片更换,建议图片大小是:640*120)","2","（点击图片更换,建议图片大小是:640*120)","（<a href='/vip'>普通vip用户才能更换</a>)")<br/>
        <a #if($yonghu.style > 0)href="javascript:selectad(2);"#end><img src="$!ad1.url" style="width: 100%;" id="imgad2" /></a>
        <input type="text" $funhelper.encode($yonghu.style,"1","","2","","disabled") style="width: 100%;" id="txtad2" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad1.link" />
        </p>

        <p>广告3$funhelper.encode($yonghu.style,"2","（点击图片更换,建议图片大小是:640*120)","（<a href='/vip'>高级vip用户才能更换</a>)")<br/>
        <a #if($yonghu.style > 1)href="javascript:selectad(3);"#end><img src="$!ad2.url" style="width: 100%;" id="imgad3"/></a>
        <input type="text" $funhelper.encode($yonghu.style,"2","","disabled") style="width: 100%;" id="txtad3" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad2.link"  />
        </p>

        <p>如果广告图片尺寸不合适，我们会直接裁切图像中间部分。</p>
        #if($yonghu.style == 0)
        <p>免费用户只允许更换一条广告,普通VIP能更换两条广告,高级VIP能更换三条广告。<a href="javascript:location.href='vip';">点击成为VIP</a></p>
        #end
        
        <a data-role="button" href="#" id="savead" data-theme="c">#if("$!code"!="")保存并预览#else保存#end</a>
        <a data-role="button" href="/hello">返回广告加介绍</a>
    </div>
</div>
#parse("/layout/footer.htm")

<script>

    $('#savead').on('click', function () {
        #if($yonghu.style == 0)
            if (tupianlink1 == "") {
                alert("未上传广告1的图片");
                return false;
            }
        #end

        #if($yonghu.style > 0)
            if (tupianlink1 == "" && tupianlink2 == ""  && tupianlink3 == "" ) {
                alert("至少要上传一条广告");
                return false;
            }
        #end

        var txt1 = $("#txtad1").val();
        var txt2 = $("#txtad2").val();
        var txt3 = $("#txtad3").val();

        $.post("setsave",{t1:tupianlink1,l1:txt1,t2:tupianlink2,l2:txt2,t3:tupianlink3,l3:txt3},function (ret) {
            #if("$!code"!="")
                location.href="/s?u=$!code";
                #else
            alert('广告设置成功!'); 
            #end
        });
    });

</script>






